package com.ws.system.user.controller;


import cn.hutool.core.util.StrUtil;
import com.ws.common.base.BaseUtils;
import com.ws.common.result.entity.ResultEntity;
import com.ws.system.user.service.ISystemUserService;
import com.ws.system.user.service.impl.SystemUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ws.system.user.entity.SystemUser;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.ws.common.base.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author weifucheng
 * @since 2019-10-26
 */
@RestController
@RequestMapping("/system/user")
public class SystemUserController extends BaseController<SystemUser> {

    @Autowired
    private ISystemUserService userService;

    @RequestMapping("/list")
    @ResponseBody
    public ResultEntity list(SystemUser user, Integer current, Integer size){
        return ResultEntity.succes(userService.list(user, current, size));
    }

    @RequestMapping("/save")
    public ResultEntity save(SystemUser user){
        BaseUtils.setDefault(user);
        if(StrUtil.isEmpty(user.getRealName())){
            user.setRealName(user.getUserName());
        }
        if(StrUtil.isEmpty(user.getId())){
            SystemUser t=userService.readByUserName(user.getUserName());
            if(t!=null){
                return ResultEntity.error("用户名已存在");
            }
        }
        return ResultEntity.succes(iService.saveOrUpdate(user));
    }

}
